#include "OptionState.h"
#include "Game.h"

OptionState::OptionState(Resources* res)
:State(res)
{
	_current_state = _next_state = ST_Option;
	_sound = new Sprite(_resources->Check, 2, 2, 0.1f);
	if (_onSound)
		_sound->Next(0);
	else
		_sound->Next(1);

	_music = new Sprite(_resources->Check, 2, 2, 0.1f);
	if (_onMusic)
		_music->Next(0);
	else
		_music->Next(1);

	_choose = new Sprite(_resources->CCC, 1, 1, 0.1f);

	_posX = 230;
	_posY = 300;
}


OptionState::~OptionState()
{
}

void OptionState::Update(float time)
{

}

void OptionState::ProcessInput(Input* input)
{
	int key = input->OnKeyDown();

	switch (key)
	{
	case DIK_ESCAPE:
		_next_state = ST_Menu;
		_close = true;
		break;
	case DIK_UP:
	case DIK_DOWN:
		if (_posY == 300) _posY = 410;
		else _posY = 300;
		break;
	case DIK_RETURN:
		if (_posY == 410)
		{
			if (_sound->Index() == 0)
			{
				_sound->Next(1);
				_onSound = false;
			}
			else
			{
				_sound->Next(0);
				_onSound = true;
			}
		}
		else
		{
			if (_music->Index() == 0)
			{
				_music->Next(1);
				_resources->_audio->StopSound(_resources->Background);
				_onMusic = false;
			}
			else
			{
				_music->Next(0);
				_resources->_audio->PlaySoundA(_resources->Background);
				_onMusic = true;
			}
		}
	default:
		break;
	}
}

void OptionState::Render(LPD3DXSPRITE spriteHandler)
{
	_resources->_pd3ddv->StretchRect(_resources->_bgOption->GetImage(), NULL, _resources->_back_buffer, NULL, D3DTEXF_NONE);
	_sound->Render(spriteHandler, 100, 410);
	_music->Render(spriteHandler, 100, 300);

	_choose->Render(spriteHandler, _posX, _posY);
}

void OptionState::Release()
{

}